/*
 * Funambol is a mobile platform developed by Funambol, Inc.
 * Copyright (C) 2008 Funambol, Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 *
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#import <Foundation/Foundation.h>

#import "spds/constants.h"

/**
 * This class is an objective c wrapper singleton to the funambol api SDK
 * Use the FunambolAPIWapperImpl to connect to the API
 */
@class FunambolAPI;

@interface FunambolAPI : NSObject {
    FunambolAPI* funAPIInstance;
    bool contactF;
    bool calendarF;
    bool noteF;
}

- (id)init;
+ (FunambolAPI*) getInstance;

/**
 * Starts the sync of Contacts.
 *
 * @param id listener the listener to pass to the sync manager
 * @return error code
 */
- (int) syncContacts:(id)listener;


/**
 * Starts the sync of Contacts.
 *
 * @param id listener the listener to pass to the sync manager
 * @return error code
 */
- (int) syncCalendar:(id)listener;


/**
 * Starts the sync of Contacts.
 *
 * @param id listener the listener to pass to the sync manager
 * @return error code
 */
- (int) syncNotes:(id)listener;


/**
 * Starts the sync of Contacts.
 *
 * @param id listener the listener to pass to the sync manager
 * @return error code
 */
- (int) syncAll:(id)listener;

/**
 * Starts the sync of contacts in a new thread
 * it calls the syncContacts:(id)listener method
 * @param id listener the listener to pass to the sync manager
 */
- (void) syncContactsInThread:(id)listener;

/**
 * Starts the sync of contacts in a new thread
 * it calls the syncContacts:(id)listener method
 * @param id listener the listener to pass to the sync manager
 */
- (void) syncCalendarInThread:(id)listener;

/**
 * Starts the sync of contacts in a new thread
 * it calls the syncContacts:(id)listener method
 * @param id listener the listener to pass to the sync manager
 */
- (void) syncNotesInThread:(id)listener;

/**
 * Starts the sync of contacts in a new thread
 * it calls the syncContacts:(id)listener method
 * @param id listener the listener to pass to the sync manager
 */
- (void) syncAllInThread:(id)listener;


/**
 * Starts the process of cleanup of the addressbook in a new thread
 * it calls the cleanupContacts:(id)listener method
 * @param id listener the listener to pass to the sync manager
 */
- (void) cleanupContactsInThread:(id)listener;

- (void) setRecoverMode:(NSString*) mode;
- (void) recoverContactsInThread:(id)listener;

/**
 * get the last sync timestamp value for the syncsource passed as param
 * @param NSString* sourceName the name of the source 
 * @return int the last sync value 
 */
- (int) getSyncSourceLastSyncDate:(NSString*) sourceName;

/**
 * save the configuration for the account
 *
 * @param NSString* url the sync server url default is http://my.funambol.com
 * @param NSString* username the username value
 * @param NSString* password the password value
 */
- (void) saveSyncConfig:(NSString*) url
               username:(NSString*) username
               password:(NSString*) password;

/**
 * load the configuration for the account
 *
 * @param NSString* url the sync server url where the value will be stored
 * @param NSString* username the username value where the value will be stored
 * @param NSString* password the password value where the value will be stored
 */
- (void) loadSyncConfig:(NSString**) url
               username:(NSString**) username
               password:(NSString**) password;
/**
 * Set the sync direction 
 * 
 * @param syncModes the direction to sync two-way from-server from-client
 * @param the source
 */
- (void) setSync:(NSString*) syncModes source: (NSString*) source;

/**
 * get the sync direction
 * 
 * @param the source
 * @return NSString* the direction to sync two-way from-server from-client
 */
- (NSString*)  getSync: (NSString*) source;

/**
 * set the remote URI for the addressbook syncsource
 *
 * @param the value of the remore name of the addressbook
 */
- (void) setURI:(NSString*) URI syncsourcename:(NSString*) syncsourcename;

/**
 * get the remote URI of the syncsource
 *
 * @return NSStringé the remote name
 */
- (NSString*)  getURI:(NSString*) syncsourcename;

/**
 * save the URL value 
 * @param NSString* the value to store in the conf
 */
- (void) saveURLConfig:(NSString*) url;

/**
 * save the Username value 
 * @param NSString* the value to store in the conf
 */
- (void) saveUsernameConfig:(NSString*) username;

/**
 * save the Password value 
 * @param NSString* the value to store in the conf
 */
- (void) savePasswordConfig:(NSString*) password;

/**
 * set the log level: 
 * 0 error
 * 1 info
 * 2 debug
 *
 * @param int the value to set the log level in the conf
 */
- (void) setLogLevel:(int) loglevel;

/**
 * get log level value
 * 0 error
 * 1 info
 * 2 debug
 *
 * return int the value to set the log level in the conf
 */
- (int) getLogLevel;
- (void) stopSyncContacts;
- (void) stopSyncAndExit;

- (void) cleanupInThread:(id) listener contactFlag:(bool)contactFlag 
            calendarFlag:(bool)calendarFlag noteFlag:(bool)noteFlag;

#ifndef FUNAMBOL_APP_STORE
-(int) cleanup: (id) listener;
#endif
@end
